package com.huike.clues.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huike.clues.domain.SysDictData;

import com.huike.clues.domain.dto.SysDictDataQueryDTO;
import com.huike.clues.mapper.SysDictDataMapper;
import com.huike.clues.service.ISysDictDataService;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.domain.entity.SysDictDataDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper,SysDictData> implements ISysDictDataService {
    @Autowired
    private SysDictDataMapper sysDictDataMapper;
    /**
     * 根据字典类型查询字典数据
     *
     * @param dictType 字典类型
     * @return 字典数据集合信息
     */
    @Override
    public List<SysDictData> selectDictDataByType(String dictType) {
        return  sysDictDataMapper.selectDictDataByType(dictType);
    }

    /**
     * 分页查询
     *
     * @param sysDictDataQueryDTO
     * @return
     */
    @Override
    public List<SysDictData> selectAll(SysDictDataQueryDTO sysDictDataQueryDTO) {
        return this.list(Wrappers.<SysDictData>lambdaQuery().eq(SysDictData::getDictType,sysDictDataQueryDTO.getDictType()));
    }

    @Override
    public void Add(SysDictData sysDictData) {
         this.save(sysDictData);
        //字典标签不能为空，字典标签长度不能超过100个字符
        if(sysDictData.getDictLabel()==null||sysDictData.getDictLabel().length()>100){
            throw new RuntimeException("字典标签不能为空，字典标签长度不能超过100个字符");
        }
        //字典键值不能为空，字典键值长度不能超过100个字符
        if(sysDictData.getDictValue()==null||sysDictData.getDictValue().length()>100){
           throw new RuntimeException("字典键值不能为空，字典键值长度不能超过100个字符");
        }
    }


}
